package dao;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.classic.Session;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import to.Curso;
import util.HibernateUtil;

public class CursoDAO {

	public List<Curso> listaCurso() {

		List<Curso> listaCurso = new ArrayList<Curso>();
		Session session = null;

		try {
			session = HibernateUtil.getSessionFactory().openSession();
			Criteria criteria = session.createCriteria(Curso.class, "cur");
			criteria.addOrder(Order.asc("cur.nome"));
			listaCurso = (List<Curso>) criteria.list();

		} catch (Exception e) {
			e.printStackTrace();
		}

		return listaCurso;
	}
	
	public Curso buscarCursoPorCodigoLegado(Integer idOrion) {

		Curso c = new Curso();
		Session session = null;

		try {
			session = HibernateUtil.getSessionFactory().openSession();
			Criteria criteria = session.createCriteria(Curso.class, "cur");
			criteria.add(Restrictions.eq("cur.idOrion", idOrion));
			c = (Curso) criteria.uniqueResult();

		} catch (Exception e) {
			e.printStackTrace();
		}
		return c;
	}

}
